package com.mall.web.control.jiance;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.alibaba.fastjson.JSONArray;
import com.mall.biz.ImageUploadBizImpl;
import com.mall.client.ps.PsTaskService;
import com.mall.client.ps.PsTimeService;
import com.mall.client.user.UserService;
import com.mall.common.Consts.PsTaskStatus;
import com.mall.common.util.PageUtil;
import com.mall.pojo.PsTask;
import com.mall.pojo.PsTaskExample;
import com.mall.pojo.PsTaskExample.Criteria;
import com.mall.pojo.PsTime;
import com.mall.pojo.User;
import com.mall.pojo.UserExample;
import com.mall.query.Page;
import com.mall.vo.ps.PsTaskRemark;
import com.mall.vo.ps.PsTaskVO;
import com.mall.web.util.HttpUtil;
import com.mall.web.util.WebUtil;
import com.mall.web.vo.ResponseEntity;

@Controller
@RequestMapping("/ps/task/")
public class PsTaskController {
	private final static Logger log = LoggerFactory.getLogger(PsTaskController.class);
	private final static Integer onlyKey = 7;
	private final static int version = 1;
	@Autowired
	private PsTaskService psTaskService;
	@Autowired
	private UserService userService;
	@Autowired
	private PsTimeService psTimeService;
	@Autowired
	private ImageUploadBizImpl imageUploadBiz;

	private final int KEFU_ZHIDING_TYPE = 2;// 客服指定的时候的type值
	private final int DEF_TYPE = 1;// 默认的type值

	/**
	 * 客服提交任务页面
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("index")
	public String index(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		Long userId = HttpUtil.getLongValueFromRequest(request, "userId");
		if (userId == null || userId <= 0) {
			log.error("客服userId为null");
			return "redirect:/ps/task/error.htm?userId=" + userId;
		}
		User user = this.userService.getUserByUserId(userId);
		List<User> userList = getInstallerOnLion();
		modelMap.put("userList", userList);
		modelMap.put("user", user);
		modelMap.put("userId", userId);
		return "ps/task/index";

	}

	/**
	 * 上传远程id和密码的图片
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 * @param pic
	 */
	@RequestMapping("addPicjson")
	@ResponseBody
	public void addDiscoverPic(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap,
			@RequestParam("pic") MultipartFile pic) {
		ResponseEntity<String> responseEntity = new ResponseEntity<>();
		String image = imageUploadBiz.uploadImage(pic, "psInstall", request);
		responseEntity.initSuccResponseEntity(image, "success");
		HttpUtil.ajaxJsonpOutput("", responseEntity, response);
	}

	/**
	 * 提交任务接口
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("confirmPsTaskAction")
	public String confirmPsTaskAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		Long userId = HttpUtil.getLongValueFromRequest(request, "userId");
		User user = this.userService.getUserByUserId(userId);
		String title = HttpUtil.getStringValueFromRequest(request, "title");
		if (StringUtils.isBlank(title)) {
			log.error("没有任务标题");
			return "redirect:/ps/task/error.htm?userId=" + userId;
		}
		Integer priority = HttpUtil.getIntegerValueFromRequest(request, "priority");// 任务的优先级
		String attribute = HttpUtil.getStringValueFromRequest(request, "attribute");
		String pic = HttpUtil.getStringValueFromRequest(request, "pic");
		Integer taskNum = HttpUtil.getIntegerValueHasDefaultFromRequest(request, "num", 1);
		Long installerId = HttpUtil.getLongValueHasDefaultFromRequest(request, "installerId", 0l);
		// String beizhu = null;
		// if (StringUtils.isNotBlank(attribute)) {
		// beizhu = user.getUserName()+":"+attribute;
		// }
		PsTask psTask = new PsTask();
		String jsonOttributeList = null;
		if (StringUtils.isNotBlank(attribute)) {
			PsTaskRemark psTaskRemark = new PsTaskRemark();
			psTaskRemark.setUserId(userId);
			psTaskRemark.setUserName(user.getUserName());
			psTaskRemark.setContent(attribute);
			psTaskRemark.setGmtCreate(new Date());
			jsonOttributeList = addObjectToJson(psTask.getAttribute(), psTaskRemark);
		}
		psTask.setTaskNum(taskNum);
		psTask.setAttribute(jsonOttributeList);
		if (StringUtils.isNotBlank(title)) {
			psTask.setTitle(title);
		}
		psTask.setCustomerId(userId);// 提交任务的客服id
		if (installerId != null && installerId > 0) {
			psTask.setStatus(PsTaskStatus.STATUS_RECEIVE);// 客服指派任务的时候
			psTask.setType(KEFU_ZHIDING_TYPE);
		} else {
			psTask.setStatus(PsTaskStatus.STATUS_NEW);// 新建任务
			psTask.setType(DEF_TYPE);
		}

		psTask.setInstallerId(installerId);// 新任务无人安装
		psTask.setLastVersion(version);
		if (priority == null) {
			psTask.setPriority(0);
		} else {
			psTask.setPriority(priority);
		}
		if (StringUtils.isNotBlank(pic)) {
			psTask.setTeamViewer(pic);
		}
		psTask.setReceiveTime(new Date());
		psTask.setFinishTime(new Date());
		Integer result = this.psTaskService.insertPsTask(psTask);
		if (result == null || result <= 0) {
			log.error("提交任务失败");
			return "redirect:/ps/task/error.htm?userId=" + userId;
		}
		return "redirect:/ps/task/index.htm?userId=" + userId;

	}

	/**
	 * 安装列表
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("install")
	public String installList(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		Integer status = HttpUtil.getIntegerValueHasDefaultFromRequest(request, "status", 0);
		installListMap(request, response, modelMap, status);

		return "ps/task/installList";

	}

	/**
	 * 给安装师傅提醒有多少未安装
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("sendTaskNum")
	@ResponseBody
	public ResponseEntity<Integer> sendTaskNum(HttpServletRequest request, HttpServletResponse response,
			ModelMap modelMap) {
		ResponseEntity<Integer> responseEntity = new ResponseEntity<>();
		Long longDate = HttpUtil.getLongValueFromRequest(request, "timeStr");
		if (longDate != null && longDate > 0) {
			Date date = new Date(longDate);
			// Long installerId = HttpUtil.getLongValueFromRequest(request,
			// "installerId");
			PsTaskExample exampleCount = getPsTaskExampleByPageAndStatus(null, PsTaskStatus.STATUS_NEW, null, null,
					date, null, null);
			int notFinishcount = this.psTaskService.getNotFinishTaskCountByexample(exampleCount);// 没有认领和没完成的任务数量
			responseEntity.initSuccResponseEntity(notFinishcount, "success");
			return responseEntity;
		}

		responseEntity.initErrorResponseEntity(null, "data is null");
		return responseEntity;
	}

	/**
	 * 被指定任务时候提示安装数量
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("appointedTaskNumJson")
	@ResponseBody
	public ResponseEntity<Integer> appointedTaskNumJson(HttpServletRequest request, HttpServletResponse response,
			ModelMap modelMap) {
		ResponseEntity<Integer> responseEntity = new ResponseEntity<>();
		Long longDate = HttpUtil.getLongValueFromRequest(request, "timeStr");
		Long installerId = HttpUtil.getLongValueFromRequest(request, "installerId");
		Integer type = KEFU_ZHIDING_TYPE;
		if (longDate != null && longDate > 0) {
			Date date = new Date(longDate);
			// Long installerId = HttpUtil.getLongValueFromRequest(request,
			// "installerId");
			PsTaskExample exampleCount = getPsTaskExampleByPageAndStatus(null, PsTaskStatus.STATUS_RECEIVE, null,
					installerId, date, null, type);
			int notFinishcount = this.psTaskService.getNotFinishTaskCountByexample(exampleCount);// 没有认领和没完成的任务数量
			responseEntity.initSuccResponseEntity(notFinishcount, "success");
			return responseEntity;
		}

		responseEntity.initErrorResponseEntity(null, "data is null");
		return responseEntity;
	}

	/**
	 * 需要安装翻页
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("installListMore")
	public String installListMore(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		Integer status = HttpUtil.getIntegerValueHasDefaultFromRequest(request, "status", 0);
		installListMap(request, response, modelMap, status);
		return "ps/task/installListMore";

	}

	private ModelMap installListMap(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap,
			Integer status) {
		Date date = new Date();
		long longDate = date.getTime();
		Long userId = HttpUtil.getLongValueFromRequest(request, "userId");
		// Date date = HttpUtil.getDateValueFromRequest(request, "date");
		Long installerId = HttpUtil.getLongValueFromRequest(request, "installerId");
		User user = null;
		if (installerId != null && installerId > 0) {
			user = this.userService.getUserByUserId(installerId);
		} else if (userId != null && userId > 0) {
			user = this.userService.getUserByUserId(userId);
		}
		Page page = new Page();
		int pageNo = HttpUtil.getIntegerValueHasDefaultFromRequest(request, "pageNo", 1);
		int pageSize = HttpUtil.getIntegerValueHasDefaultFromRequest(request, "pageSize", PageUtil.PAGE_SIZE);
		page.setPageByPageNoAndPageSize(pageNo, pageSize);
		String sort = HttpUtil.getStringValueFromRequest(request, "sort");

		PsTaskExample example = getPsTaskExampleByPageAndStatus(page, status, sort, installerId, null, null, null);
		// PsTaskExample exampleCount =
		// getPsTaskExampleByPageAndStatus(null,status, sort,installerId,null);
		List<PsTask> psTaskList = this.psTaskService.getPsTaskListByExample(example);
		Integer count = this.psTaskService.getCountByExample(example);
		List<PsTaskVO> psTaskVOList = getpsTaskVOList(psTaskList);
		Integer taskSum = this.psTaskService.getTaskSumByExample(example);
		// int notFinishcount =
		// this.psTaskService.getNotFinishTaskCountByexample(exampleCount);//没有认领和没完成的任务数量
		modelMap.put("longDate", longDate);
		modelMap.put("psTaskVOList", psTaskVOList);
		modelMap.put("userId", userId);
		modelMap.put("installerId", installerId);
		modelMap.put("user", user);
		modelMap.put("status", status);
		modelMap.put("sort", sort);
		modelMap.put("pageNo", pageNo);
		modelMap.put("count", count);
		modelMap.put("taskSum", taskSum);
		modelMap.put("pageCount", PageUtil.getPageNO(count, pageSize));
		// modelMap.put("notFinishcount", notFinishcount);
		return modelMap;
	}

	public List<PsTaskVO> getpsTaskVOList(List<PsTask> psTaskList) {
		if (psTaskList == null || psTaskList.size() <= 0) {
			return null;
		}
		List<PsTaskVO> psTaskVOList = new ArrayList<>();
		PsTaskVO psTaskVO = null;
		PsTask psTask = null;
		for (int i = 0; i < psTaskList.size(); i++) {
			psTaskVO = new PsTaskVO();
			psTask = psTaskList.get(i);
			psTaskVO.setPsTask(psTask);
			psTaskVO.setUser(this.userService.getUserByUserId(psTask.getCustomerId()));
			psTaskVO.setInstallUser(this.userService.getUserByUserId(psTask.getInstallerId()));
			if (StringUtils.isNotBlank(psTask.getAttribute())) {
				String json = psTask.getAttribute();
				List<PsTaskRemark> psTaskRemarkList = null;
				if (StringUtils.isNotBlank(json)) {
					psTaskRemarkList = JSONArray.parseArray(json, PsTaskRemark.class);
				}
				psTaskVO.setPsTaskRemarkList(psTaskRemarkList);
			}
			psTaskVOList.add(psTaskVO);

		}

		return psTaskVOList;

	}

	private PsTaskExample getPsTaskExampleByPageAndStatus(Page page, Integer status, String sort, Long userId,
			Date date, Long customerId, Integer type) {
		PsTaskExample example = new PsTaskExample();
		if (StringUtils.isNotBlank(sort)) {
			example.setOrderByClause(sort);
		} else {
			example.setOrderByClause("gmt_modify desc");
		}
		if (page != null) {
			example.setStart(page.getBegin());
			example.setLimit(page.getLength());
		}
		Criteria criteria = example.createCriteria();
		if (status != null) {
			criteria.andStatusEqualTo(status);
		}
		if (userId != null && userId > 0) {
			criteria.andInstallerIdEqualTo(userId);
		}
		if (customerId != null && customerId > 0) {
			criteria.andCustomerIdEqualTo(customerId);
		}
		if (date != null) {
			criteria.andGmtCreateGreaterThan(date);
		}
		if (type != null && type > 0) {
			criteria.andTypeEqualTo(type);
		}
		return example;

	}

	/**
	 * 安装领取任务
	 * 
	 * @param request
	 * @param response
	 * @return
	 */

	@RequestMapping("receiveTaskJson")
	@ResponseBody
	public ResponseEntity<Boolean> receiveTaskJson(HttpServletRequest request, HttpServletResponse response) {
		ResponseEntity<Boolean> responseEntity = new ResponseEntity<>();
		Integer type = HttpUtil.getIntegerValueHasDefaultFromRequest(request, "type", 1);
		Long installerId = HttpUtil.getLongValueFromRequest(request, "installerId");
		if (installerId == null || installerId <= 0) {
			responseEntity.initErrorResponseEntity(false, "安装用户不存在");
			return responseEntity;
		}

		Long psTaskId = HttpUtil.getLongValueFromRequest(request, "psTaskId");
		if (psTaskId == null || psTaskId <= 0) {
			responseEntity.initErrorResponseEntity(false, "任务id错误");
			return responseEntity;
		}
		PsTask psTask = this.psTaskService.getPsTaskById(psTaskId);
		if (psTask == null) {
			responseEntity.initErrorResponseEntity(false, "任务错误");
			return responseEntity;
		}
		if (psTask.getStatus() == 1) {
			responseEntity.initErrorResponseEntity(false, "任务已经领取");
			responseEntity.setCode("-500");
			return responseEntity;
		}
		// if (psTask.getLastVersion()!= version) {
		// responseEntity.initErrorResponseEntity(false, "任务已经被领取");
		// responseEntity.setCode("-500");
		// return responseEntity;
		// }
		Map<String, Object> psTaskMap = new HashMap<String, Object>();
		psTaskMap.put("status", PsTaskStatus.STATUS_RECEIVE);
		psTaskMap.put("installerId", installerId);
		psTaskMap.put("psTaskId", psTaskId);
		psTaskMap.put("version", psTask.getLastVersion());
		psTaskMap.put("type", type);

		boolean success = this.psTaskService.updateByIdAndVersion(psTaskMap);
		if (success) {
			responseEntity.initSuccResponseEntity(true, "receive task success");
			return responseEntity;
		}
		responseEntity.initErrorResponseEntity(false, "任务已经被领取");
		responseEntity.setCode("-500");
		return responseEntity;

	}

	/**
	 * 客服确认完成安装
	 * 
	 * @param request
	 * @param response
	 * @return
	 */

	@RequestMapping("finishTaskJson")
	@ResponseBody
	public ResponseEntity<Boolean> finishTaskJson(HttpServletRequest request, HttpServletResponse response) {
		Integer status = HttpUtil.getIntegerValueFromRequest(request, "status");
		ResponseEntity<Boolean> responseEntity = new ResponseEntity<>();
		Long installerId = HttpUtil.getLongValueFromRequest(request, "installerId");
		if (installerId == null || installerId <= 0) {
			responseEntity.initErrorResponseEntity(false, "安装用户不存在");
			return responseEntity;
		}
		if (status == null ) {
			responseEntity.initErrorResponseEntity(false, "status is null");
			return responseEntity;
		}
		Long psTaskId = HttpUtil.getLongValueFromRequest(request, "psTaskId");
		if (psTaskId == null || psTaskId <= 0) {
			responseEntity.initErrorResponseEntity(false, "任务id错误");
			return responseEntity;
		}
		PsTask psTask = this.psTaskService.getPsTaskById(psTaskId);
		if (psTask == null) {
			responseEntity.initErrorResponseEntity(false, "任务错误");
			return responseEntity;
		}

		if (installerId.longValue() != psTask.getInstallerId().longValue()) {
			responseEntity.initErrorResponseEntity(false, "不是你的任务，你能点击完成哟");
			responseEntity.setCode("-300");
			return responseEntity;
		}
		if (psTask.getStatus() == status) {
			responseEntity.initErrorResponseEntity(false, "任务已经被完成");
			return responseEntity;
		}
		psTask.setFinishTime(new Date());
		psTask.setStatus(status);
		psTask.setInstallerId(installerId);
		Integer result = this.psTaskService.updatePsTask(psTask);
		if (result != null && result > 0) {
			responseEntity.initSuccResponseEntity(true, "finish task success");
			return responseEntity;
		}
		responseEntity.initErrorResponseEntity(false, "任务已经被完成");
		return responseEntity;

	}

	/**
	 * 无法安装的时候释放任务
	 * 
	 * @param request
	 * @param response
	 * @return
	 */

	@RequestMapping("releaseTaskJson")
	@ResponseBody
	public ResponseEntity<Boolean> releaseTaskJson(HttpServletRequest request, HttpServletResponse response) {
		ResponseEntity<Boolean> responseEntity = new ResponseEntity<>();
		Long installerId = HttpUtil.getLongValueFromRequest(request, "installerId");
		if (installerId == null || installerId <= 0) {
			responseEntity.initErrorResponseEntity(false, "安装用户不存在");
			return responseEntity;
		}
		Long psTaskId = HttpUtil.getLongValueFromRequest(request, "psTaskId");
		if (psTaskId == null || psTaskId <= 0) {
			responseEntity.initErrorResponseEntity(false, "任务id错误");
			return responseEntity;
		}
		PsTask psTask = this.psTaskService.getPsTaskById(psTaskId);
		if (psTask == null) {
			responseEntity.initErrorResponseEntity(false, "任务错误");
			return responseEntity;
		}

		if (installerId.longValue() != psTask.getInstallerId().longValue()) {
			responseEntity.initErrorResponseEntity(false, "不是你的任务，你能点击释放哟");
			responseEntity.setCode("-300");
			return responseEntity;
		}
		if (psTask.getStatus() == PsTaskStatus.STATUS_NEW || psTask.getStatus() == PsTaskStatus.STATUS_FINISH) {
			responseEntity.initErrorResponseEntity(false, "任务还未领取或已经完成");
			return responseEntity;
		}
		User user = this.userService.getUserByUserId(installerId);
		if (user == null) {
			responseEntity.initErrorResponseEntity(false, "任务错误");
			return responseEntity;
		}
		PsTaskRemark psTaskRemark = new PsTaskRemark();
		psTaskRemark.setUserId(installerId);
		psTaskRemark.setUserName(user.getUserName());
		psTaskRemark.setContent("安装失败释放任务");
		psTaskRemark.setGmtCreate(new Date());

		String jsonOttributeList = addObjectToJson(psTask.getAttribute(), psTaskRemark);
		psTask.setAttribute(jsonOttributeList);
	 
		psTask.setLastVersion(1);
		psTask.setInstallerId(0l);// 释放后无人安装状态
		Integer result = this.psTaskService.updatePsTask(psTask);
		if (result != null && result > 0) {
			responseEntity.initSuccResponseEntity(true, "finish task success");
			return responseEntity;
		}
		responseEntity.initErrorResponseEntity(false, "任务已经被完成");
		return responseEntity;

	}

	/**
	 * 修改备注
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("modifyPsTaskAction")
	@ResponseBody
	public ResponseEntity<Boolean> modifyPsTaskAction(HttpServletRequest request, HttpServletResponse response,
			ModelMap modelMap) {
		ResponseEntity<Boolean> responseEntity = new ResponseEntity<>();
		Long userId = HttpUtil.getLongValueFromRequest(request, "userId");
		User user = this.userService.getUserByUserId(userId);
		String attribute = HttpUtil.getStringValueFromRequest(request, "attribute");
		Long psTaskId = HttpUtil.getLongValueFromRequest(request, "psTaskId");
		PsTask psTask = this.psTaskService.getPsTaskById(psTaskId);
		if (psTask == null) {
			responseEntity.initErrorResponseEntity(false, "任务不存在");
			return responseEntity;
		}
		PsTaskRemark psTaskRemark = new PsTaskRemark();
		if (StringUtils.isNotBlank(attribute)) {

			psTaskRemark.setUserId(userId);
			psTaskRemark.setUserName(user.getUserName());
			psTaskRemark.setContent(attribute);
			psTaskRemark.setGmtCreate(new Date());
		}
		String jsonOttributeList = addObjectToJson(psTask.getAttribute(), psTaskRemark);
		psTask.setAttribute(jsonOttributeList);
		Integer result = this.psTaskService.updatePsTask(psTask);
		if (result != null && result > 0) {
			responseEntity.initSuccResponseEntity(true, "finish task success");
			return responseEntity;
		}
		responseEntity.initErrorResponseEntity(false, "任务已经被完成");
		return responseEntity;

	}

	/**
	 * 修改图片
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("modifyPicAction")
	@ResponseBody
	public ResponseEntity<Boolean> modifyPicAction(HttpServletRequest request, HttpServletResponse response,
			ModelMap modelMap) {
		ResponseEntity<Boolean> responseEntity = new ResponseEntity<>();
		// Long userId = HttpUtil.getLongValueFromRequest(request, "userId");
		// User user = this.userService.getUserByUserId(userId);
		String pic = HttpUtil.getStringValueFromRequest(request, "pic");
		Long psTaskId = HttpUtil.getLongValueFromRequest(request, "psTaskId");
		PsTask psTask = this.psTaskService.getPsTaskById(psTaskId);
		if (psTask == null) {
			responseEntity.initErrorResponseEntity(false, "任务不存在");
			return responseEntity;
		}
		psTask.setTeamViewer(pic);
		Integer result = this.psTaskService.updatePsTask(psTask);
		if (result != null && result > 0) {
			responseEntity.initSuccResponseEntity(true, "finish task success");
			return responseEntity;
		}
		responseEntity.initErrorResponseEntity(false, "任务已经被完成");
		return responseEntity;

	}

	/**
	 * 安装师傅的安装列表
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("myInstall")
	public String myInstall(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		Integer status = HttpUtil.getIntegerValueHasDefaultFromRequest(request, "status", 1);
		installListMap(request, response, modelMap, status);
		return "ps/task/myInstall";

	}

	/**
	 * 加载更多
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */

	@RequestMapping("myInstallMore")
	public String myInstallMore(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		Integer status = HttpUtil.getIntegerValueHasDefaultFromRequest(request, "status", 1);
		installListMap(request, response, modelMap, status);
		return "ps/task/myInstallMore";

	}

	/**
	 * 客服发布任务的列表
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("myIssueTask")
	public String myIssueTask(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		Integer status = HttpUtil.getIntegerValueHasDefaultFromRequest(request, "status", 0);
		TaskListMap(request, response, modelMap, status);
		return "ps/task/myIssueTask";
	}

	/**
	 * 加载更多
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("myIssueTaskMore")
	public String myIssueTaskMore(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		Integer status = HttpUtil.getIntegerValueHasDefaultFromRequest(request, "status", 0);
		TaskListMap(request, response, modelMap, status);
		return "ps/task/myIssueTaskMore";
	}

	// @RequestMapping("appointedTaskAction")
	// @ResponseBody
	// public ResponseEntity<Boolean> appointedTaskAction(HttpServletRequest
	// request, HttpServletResponse response, ModelMap modelMap){
	// ResponseEntity<Boolean> responseEntity = new ResponseEntity<>();
	// Long installerId = HttpUtil.getLongValueFromRequest(request,
	// "installerId");
	// if (installerId == null || installerId<=0) {
	// responseEntity.initErrorResponseEntity(false, "安装用户不存在");
	// return responseEntity;
	// }
	//
	// Long psTaskId = HttpUtil.getLongValueFromRequest(request, "psTaskId");
	// if (psTaskId == null || psTaskId<=0) {
	// responseEntity.initErrorResponseEntity(false, "任务id错误");
	// return responseEntity;
	// }
	// PsTask psTask = this.psTaskService.getPsTaskById(psTaskId);
	// if (psTask == null) {
	// responseEntity.initErrorResponseEntity(false, "任务错误");
	// return responseEntity;
	// }
	// if (psTask.getStatus() != 0) {
	// responseEntity.initErrorResponseEntity(false, "任务已经领取");
	// responseEntity.setCode("-500");
	// return responseEntity;
	// }
	// Map<String, Object> psTaskMap = new HashMap<String, Object>();
	// psTaskMap.put("status", PsTaskStatus.STATUS_RECEIVE);
	// psTaskMap.put("installerId", installerId);
	// psTaskMap.put("psTaskId", psTaskId);
	// psTaskMap.put("version",psTask.getLastVersion());
	//
	// boolean success =
	// this.psTaskService.updateByIdAndVersionAndCustomerId(psTaskMap);
	// if (success) {
	// responseEntity.initSuccResponseEntity(true, "receive task success");
	// return responseEntity;
	// }
	// responseEntity.initErrorResponseEntity(false, "任务已经被领取");
	// responseEntity.setCode("-500");
	// return responseEntity;
	//
	// }
	//
	@RequestMapping("error")
	public String error(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		return "ps/task/error";

	}

	private ModelMap TaskListMap(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap,
			Integer status) {
		Long customerId = HttpUtil.getLongValueFromRequest(request, "customerId");
		User user = null;
		if (customerId != null && customerId > 0) {
			user = this.userService.getUserByUserId(customerId);
		}
		Page page = new Page();
		int pageNo = HttpUtil.getIntegerValueHasDefaultFromRequest(request, "pageNo", 1);
		int pageSize = HttpUtil.getIntegerValueHasDefaultFromRequest(request, "pageSize", PageUtil.PAGE_SIZE);
		page.setPageByPageNoAndPageSize(pageNo, pageSize);
		String sort = HttpUtil.getStringValueFromRequest(request, "sort");

		PsTaskExample example = getPsTaskExampleByPageAndStatus(page, status, sort, null, null, customerId, null);
		// PsTaskExample exampleCount =
		// getPsTaskExampleByPageAndStatus(null,status, sort,installerId,null);
		List<PsTask> psTaskList = this.psTaskService.getPsTaskListByExample(example);
		Integer count = this.psTaskService.getCountByExample(example);
		List<PsTaskVO> psTaskVOList = getpsTaskVOList(psTaskList);
		List<User> userList = getInstallerOnLion();
		modelMap.put("userList", userList);
		// int notFinishcount =
		// this.psTaskService.getNotFinishTaskCountByexample(exampleCount);//没有认领和没完成的任务数量
		modelMap.put("psTaskVOList", psTaskVOList);
		modelMap.put("customerId", customerId);
		modelMap.put("user", user);
		modelMap.put("status", status);
		modelMap.put("sort", sort);
		modelMap.put("pageNo", pageNo);
		modelMap.put("count", count);
		modelMap.put("pageCount", PageUtil.getPageNO(count, pageSize));
		// modelMap.put("notFinishcount", notFinishcount);
		return modelMap;
	}

	@RequestMapping("register")
	public String register(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		return "ps/task/register";

	}

	@RequestMapping("registerAction")
	@ResponseBody
	public ResponseEntity<Long> registerAction(HttpServletRequest request, HttpServletResponse response,
			ModelMap modelMap) {
		ResponseEntity<Long> responseEntity = new ResponseEntity<>();

		String phone = HttpUtil.getStringValueFromRequest(request, "phone");
		String name = HttpUtil.getStringValueFromRequest(request, "name");
		if (StringUtils.isBlank(phone) || StringUtils.isBlank(name)) {
			responseEntity.initErrorResponseEntity(null, "register is error");
			return responseEntity;
		}

		User userPhone = this.userService.getUserByPhone(phone, onlyKey);// 校验手机号是否注册过
		if (userPhone != null) {
			responseEntity.initErrorResponseEntity(null, "phone and password is error");
			responseEntity.setCode("-300");
			return responseEntity;
		}
		User user = new User();
		user.setUserName(name);
		user.setPhone(phone);
		user.setPassword("123456");
		user.setCommOnlyKey(onlyKey);
		user.setNameAndPhone(name + phone);
		user.setCreateUserId(1l);
		user.setGmtCreate(new Date());
		user.setGmtModify(new Date());
		user.setPortrait("nan.png");
		user.setSex(Short.parseShort("0"));
		user.setLevel(Short.parseShort("1"));
		user.setIntegral(0l);
		user.setStatus(Short.parseShort("1"));
		Integer result = this.userService.insertUserByExample(user);
		if (result != null && result > 0) {
			responseEntity.initSuccResponseEntity(user.getId(), "register is success");
			return responseEntity;
		}
		responseEntity.initErrorResponseEntity(null, "phone and password is error");
		return responseEntity;

	}

	@RequestMapping("psLogin")
	public String psLogin(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		return "ps/task/psLogin";

	}

	@RequestMapping("psLoginAction")
	public String psLoginAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {

		User user = this.userService.loginPsTask(request.getParameter("phone"), request.getParameter("passWord"),
				onlyKey);
		if (user == null) {
			log.error("账号或密码错误");
			return "redirect:/ps/task/error.htm";
		}
		user.setStatus(Short.parseShort("2"));// 用户登录后在线
		user.setGmtModify(new Date());
		this.userService.modifytUserByPrimaryKey(user);
		Boolean result = insertPsTimeResult(user.getId(),2);
		if (result) {
			//return "redirect:/ps/task/index.htm?userId=" + user.getId();
			return "redirect:/ps/task/installer.htm?installerId=" + user.getId();
		}
		return "redirect:/ps/task/error.htm";

	}
	


	/**
	 * 修改用户在线和下线状态
	 */
	@RequestMapping("userStatusJson")
	@ResponseBody
	public ResponseEntity<Boolean> userStatusJson(HttpServletRequest request, HttpServletResponse response,
			ModelMap modelMap) {
		ResponseEntity<Boolean> responseEntity = new ResponseEntity<>();
		String statusStr = request.getParameter("status");
		Short status = null;
		if (StringUtils.isNotBlank(statusStr)) {
			status = Short.parseShort(statusStr);
		}

		Long userId = HttpUtil.getLongValueFromRequest(request, "userId");
		if (status == null || userId == null) {
			responseEntity.initErrorResponseEntity(false, "userId or status is null");
			return responseEntity;
		}
		User user = this.userService.getUserByUserId(userId);
		if (user == null) {
			responseEntity.initErrorResponseEntity(false, "userId or status is null");
			return responseEntity;
		}
		if (user.getStatus()==status) {
			responseEntity.initErrorResponseEntity(false, "user  status is aready online or offline");
			return responseEntity;
		}
		user.setStatus(status);
		user.setGmtModify(new Date());
		this.userService.modifytUserByPrimaryKey(user);
		Boolean result = insertPsTimeResult(user.getId(),Integer.parseInt(statusStr));
		if (result) {
			responseEntity.initSuccResponseEntity(true, "modify status is success");
			return responseEntity;
		}
		responseEntity.initErrorResponseEntity(false, "userId or status is null");
		return responseEntity;
	}

	private List<PsTaskVO> getInstallerTaskCount(Short stauts){
		UserExample example = new UserExample();
		com.mall.pojo.UserExample.Criteria criteria = example.createCriteria();
		criteria.andCommOnlyKeyEqualTo(onlyKey);
		criteria.andTypeEqualTo(6);
		criteria.andStatusEqualTo(stauts);
		List<User> userList = this.userService.getUserByExample(example);
		List<PsTaskVO> psTaskVOList = new ArrayList<>();
		PsTaskVO psTaskVO = null;
		if (userList != null && userList.size()>0) {
			for (int i = 0; i < userList.size(); i++) {
				psTaskVO = new PsTaskVO();
				User user = userList.get(i);
				PsTaskExample countExample = getPsTaskExampleByPageAndStatus(null,PsTaskStatus.STATUS_RECEIVE, null, user.getId(), null, null, null);
				Integer count = this.psTaskService.getCountByExample(countExample);
				if(user.getAttribute() !=null){
					psTaskVO.setUser(user);
					psTaskVO.setCount(count);
					psTaskVOList.add(psTaskVO);
				}
			
			}
		}
		Collections.sort(psTaskVOList, new SortByCount());
		return psTaskVOList;
		
	}
	   class SortByCount implements Comparator {
	         public int compare(Object o1, Object o2) {
	        	 PsTaskVO s1 = (PsTaskVO) o1;
	        	 PsTaskVO s2 = (PsTaskVO) o2;
	          return s1.getCount().compareTo(s2.getCount());
//	          if (s1.getAge() > s2.getAge())
//	           return 1;
//	          return -1;
	         }
	        }
	
	/**
	 * 在线安装师傅列表
	 * 
	 * @return
	 */
	private List<User> getInstallerOnLion() {
		UserExample example = new UserExample();
		com.mall.pojo.UserExample.Criteria criteria = example.createCriteria();
		criteria.andCommOnlyKeyEqualTo(onlyKey);
		criteria.andTypeEqualTo(6);
		criteria.andStatusEqualTo(Short.parseShort("2"));
		List<User> userList = this.userService.getUserByExample(example);
		return userList;
	}

	/**
	 * ObjectToJson
	 * 
	 * @param json
	 * @param psTaskRemark
	 * @return
	 */
	private static String addObjectToJson(String json, PsTaskRemark psTaskRemark) {
		String result = null;
		if (StringUtils.isBlank(psTaskRemark.getContent())) {
			result = json;
			return result;
		}
		if (StringUtils.isBlank(json)) {
			List<PsTaskRemark> ss = new ArrayList<>();
			ss.add(psTaskRemark);
			result = JSONArray.toJSONString(ss);

		} else {
			List<PsTaskRemark> aa = JSONArray.parseArray(json, PsTaskRemark.class);
			aa.add(psTaskRemark);
			result = JSONArray.toJSONString(aa);
		}

		return result;

	}
	/**
	 * 安装师傅上下线插入数据库
	 * @param userId
	 * @param status
	 * @return
	 */
	private boolean insertPsTimeResult(Long userId,Integer status){
		PsTime psTime = null;
		if (status != null && status==2) {
			psTime = new PsTime();
			psTime.setOnlineTime(new Date());
			psTime.setUserId(userId);
			psTime.setStatus(status);
			Integer result = this.psTimeService.insertPsTime(psTime);
			if (result != null && result>0) {
				return true;
			}
		}else if(status != null && status==-2){
			psTime = this.psTimeService.getPsTimeOnLine(userId,2);
			if (psTime ==null) {
				return false;
			}
			psTime.setOfflineTime(new Date());
			psTime.setStatus(status);
			Integer result = this.psTimeService.updatePsTime(psTime);
			if (result != null && result>0) {
				return true;
			}
		}
		
		return false;
//		PsTime psTime = new PsTime();
//		if (status==2) {
//			psTime.setOnlineTime(new Date());
//		}else{
//			psTime.setOfflineTime(new Date());
//		}
//		
//		psTime.setUserId(userId);
//		psTime.setStatus(status);
//		Integer result = this.psTimeService.insertPsTime(psTime);
//		if (result != null && result>0) {
//			return true;
//		}
//		return false;
		
	}

	/**
	 * 用户选择安装师傅页面
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */

	@RequestMapping("psIndex")
	public String psIndex(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		String psuuid = WebUtil.getPsUserCookieValue(request, response);//用户的ip加随机字符串
		String uuid = HttpUtil.getStringValueFromRequest(request, "uuid");
		Integer taskNum = HttpUtil.getIntegerValueHasDefaultFromRequest(request, "num", 1);
	//	PsTask psTaskUuid = this.psTaskService.getPsTaskByIpAndStatusAndNum(null,PsTaskStatus.STATUS_NEW, taskNum,uuid);
		PsTask psTaskUuid = this.psTaskService.getPsTaskByUuid(uuid);
		if (psTaskUuid.getStatus() ==PsTaskStatus.STATUS_FINISH || psTaskUuid.getStatus() ==PsTaskStatus.STATUS_REFUND) {
			return "ps/task/error";
		}
	
		PsTask psTask = this.psTaskService.getPsTaskByIpAndStatusAndNum(psuuid, PsTaskStatus.STATUS_NEW, taskNum,uuid);
		
		PsTask psTaskSend = this.psTaskService.getPsTaskByIpAndStatusAndNum(psuuid, PsTaskStatus.STATUS_RECEIVE, taskNum,uuid);
		
		
		if (psTaskSend!=null) {
			User userSend = this.userService.getUserByUserId(psTaskSend.getInstallerId());
			modelMap.put("userSend", userSend);
		}
		if (psTask != null) {
			User user = this.userService.getUserByUserId(psTask.getInstallerId());
			PsTaskExample example = getPsTaskExampleByPageAndStatus(null, PsTaskStatus.STATUS_RECEIVE, null, user.getId(), null, null, null);
			Integer count = this.psTaskService.getCountByExample(example);
			modelMap.put("user", user);
			modelMap.put("count", count);
		} else {
			List<User> userList = getInstallerOnLion();
			modelMap.put("userList", userList);
		}
		List<PsTaskVO> psTaskVOList = getInstallerTaskCount(Short.parseShort("2"));//在线客服
		
		List<PsTaskVO> offLinPsTaskVOList = getInstallerTaskCount(Short.parseShort("-2"));//离线客服
		modelMap.put("offLinPsTaskVOList", offLinPsTaskVOList);
		modelMap.put("psuuid", psuuid);
		modelMap.put("taskNum", taskNum);
		modelMap.put("psTaskVOList", psTaskVOList);
		modelMap.put("uuid", uuid);
		return "ps/task/psIndex";

	}

	/**
	 * 用户选择安装接口
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("userChoiceAction")
	@ResponseBody
	public ResponseEntity<String> userChoiceAction(HttpServletRequest request, HttpServletResponse response,
			ModelMap modelMap) {

		ResponseEntity<String> responseEntity = new ResponseEntity<>();
		String uuid = HttpUtil.getStringValueFromRequest(request, "uuid");
		Integer taskNum = HttpUtil.getIntegerValueHasDefaultFromRequest(request, "num", 1);
		String psuuid = WebUtil.getPsUserCookieValue(request, response);
		Long installerId = HttpUtil.getLongValueFromRequest(request, "installerId");
//		PsTask psTask = this.psTaskService.getPsTaskByUuid(uuid);
		PsTask psTask = this.psTaskService.getPsTaskByIpAndStatusAndNum(null, PsTaskStatus.STATUS_NEW, taskNum,uuid);
		if (psTask == null) {
			
			PsTask psTaskDian = this.psTaskService.getPsTaskByIpAndStatusAndNum(null, PsTaskStatus.STATUS_RECEIVE, taskNum,uuid);
			User userSend = this.userService.getUserByUserId(psTaskDian.getInstallerId());
			log.error("the Task is null");
			responseEntity.initErrorResponseEntity(userSend.getAttribute(), "PsTask Establish error");
			responseEntity.setCode("-300");
			return responseEntity;
		}
		
		if (StringUtils.isBlank(psTask.getTitle()) && psTask.getInstallerId() == null) {
			psTask.setTitle(psuuid);
			psTask.setType(DEF_TYPE);
			psTask.setInstallerId(installerId);
			psTask.setStatus(PsTaskStatus.STATUS_RECEIVE);// 用户主动加安装师傅qq，安装者被动接受任务
			psTask.setReceiveTime(new Date());
			Integer result = this.psTaskService.updatePsTask(psTask);
			if (result == null || result <= 0) {
				log.error("提交任务失败");
				responseEntity.initErrorResponseEntity("error", "PsTask Establish error");
				return responseEntity;
			}
			responseEntity.initSuccResponseEntity("success", "PsTask Already exists");
			responseEntity.setCode("300");
			return responseEntity;
		}else{
			User user = this.userService.getUserByUserId(psTask.getInstallerId());
			responseEntity.initSuccResponseEntity(user.getAttribute(), "PsTask Already exists");
			return responseEntity;
		}
		

	}

	/**
	 * 安装者页面
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("installer")
	public String installer(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		Date date = new Date();
		long longDate = date.getTime();
		Integer status = HttpUtil.getIntegerValueHasDefaultFromRequest(request, "status", 1);
		Long installerId = HttpUtil.getLongValueFromRequest(request, "installerId");
		User user = this.userService.getUserByUserId(installerId);
		PsTaskExample example = getPsTaskExampleByPageAndStatus(null, status, "receive_time asc", installerId, null, null, null);
		List<PsTask> psTaskList = this.psTaskService.getPsTaskListByExample(example);
		
		PsTaskExample finishExample = getPsTaskExampleByPageAndStatus(null, PsTaskStatus.STATUS_FINISH, null, installerId, null, null, null);
		Integer count = this.psTaskService.getCountByExample(finishExample);//已经完成的任务数量
		Integer taskSum = this.psTaskService.getTaskSumByExample(finishExample);//已经完成的软件数量
		PsTaskExample canNotInstallExample = getPsTaskExampleByPageAndStatus(null, PsTaskStatus.STATUS_REFUND, null, installerId, null, null, null);
		Integer refundCount = this.psTaskService.getCountByExample(canNotInstallExample);//无法安装退款的数量
		List<User> userList = getInstallerOnLion();//在线客服
		modelMap.put("userList", userList);
		modelMap.put("psTaskList", psTaskList);
		modelMap.put("count", count);
		modelMap.put("taskSum", taskSum);
		modelMap.put("user", user);
		modelMap.put("refundCount", refundCount);
		modelMap.put("longDate", longDate);
		return "ps/task/installer";

	}
	/**
	 * 客服新建任务链接
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("staff")
	public String  staff(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap){
		Long userId = HttpUtil.getLongValueFromRequest(request, "userId");
		User user = this.userService.getUserByUserId(userId);
		modelMap.put("user", user);
		return "ps/task/staff";
		
	}
	@RequestMapping("staffNewTaskAction")
	@ResponseBody
	public ResponseEntity<String>  staffNewTaskAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap){
		ResponseEntity<String> responseEntity = new ResponseEntity<>();
		Long userId = HttpUtil.getLongValueFromRequest(request, "userId");//客服id
		String uuid = UUID.randomUUID().toString().replace("-", "");
		Integer taskNum = HttpUtil.getIntegerValueHasDefaultFromRequest(request, "num", 1);
		String wangwang = HttpUtil.getStringValueFromRequest(request, "wangwang");
		Integer shopType = HttpUtil.getIntegerValueFromRequest(request , "shopType");
		if (StringUtils.isBlank(wangwang) || shopType==null || shopType<=0) {
			log.error("提交任务失败");
			responseEntity.initErrorResponseEntity("error", "wangwang or shopType is null");
			return responseEntity;
		}
		PsTask	psTask = new PsTask();
		
		psTask.setCustomerId(userId);
		psTask.setStatus(PsTaskStatus.STATUS_NEW);// 新建任务
		psTask.setLastVersion(version);
//		psTask.setTitle(null);
//		psTask.setInstallerId(installerId);
//		psTask.setReceiveTime(new Date());
//		psTask.setFinishTime(new Date());
		psTask.setType(1);
		psTask.setPriority(0);
		psTask.setTaskNum(taskNum);
		psTask.setUuid(uuid);
		psTask.setShopType(shopType);
		
		
		psTask.setQq(wangwang);//用户购买完成后客服生成链接，存用户的淘宝旺旺号
		Integer result = this.psTaskService.insertPsTask(psTask);
		if (result == null || result <= 0) {
			log.error("提交任务失败");
			responseEntity.initErrorResponseEntity("error", "PsTask Establish error");
			return responseEntity;
		}
		
		String url ="http://www.psdashi.cn/ps/task/psIndex.htm?num="+taskNum+"&uuid="+uuid;
		responseEntity.initSuccResponseEntity(url, "PsTask Already exists");
		return responseEntity;
		
	}
	
//	@RequestMapping("turnOutJson")
//	@ResponseBody
//	public ResponseEntity<Boolean> turnOutJson(HttpServletRequest request, HttpServletResponse response) {
//		ResponseEntity<Boolean> responseEntity = new ResponseEntity<>();
//		Long userId = HttpUtil.getLongValueFromRequest(request, "userId");
//		Long installerId = HttpUtil.getLongValueFromRequest(request, "installerId");
//		if (installerId == null || installerId <= 0 || userId== null || userId < 0) {
//			responseEntity.initErrorResponseEntity(false, "安装用户转出用户id不存在");
//			return responseEntity;
//		}
//		Long psTaskId = HttpUtil.getLongValueFromRequest(request, "psTaskId");
//		if (psTaskId == null || psTaskId <= 0) {
//			responseEntity.initErrorResponseEntity(false, "任务id错误");
//			return responseEntity;
//		}
//		PsTask psTask = this.psTaskService.getPsTaskById(psTaskId);
//		if (psTask == null) {
//			responseEntity.initErrorResponseEntity(false, "任务错误");
//			return responseEntity;
//		}
//
//		if (installerId.longValue() != psTask.getInstallerId().longValue()) {
//			responseEntity.initErrorResponseEntity(false, "不是你的任务，你能点击转出哟");
//			responseEntity.setCode("-300");
//			return responseEntity;
//		}
//		if (psTask.getStatus() == PsTaskStatus.STATUS_NEW || psTask.getStatus() == PsTaskStatus.STATUS_FINISH) {
//			responseEntity.initErrorResponseEntity(false, "任务还未领取或已经完成");
//			return responseEntity;
//		}
//		User user = this.userService.getUserByUserId(installerId);
//		User userTurnOut = this.userService.getUserByUserId(userId);
//		if (user == null || userTurnOut==null) {
//			responseEntity.initErrorResponseEntity(false, "任务错误");
//			return responseEntity;
//		}
//		PsTaskRemark psTaskRemark = new PsTaskRemark();
//		psTaskRemark.setUserId(installerId);
//		psTaskRemark.setUserName(user.getUserName());
//		psTaskRemark.setContent("安装失败转出给"+userTurnOut.getUserName());
//		psTaskRemark.setGmtCreate(new Date());
//
//		String jsonOttributeList = addObjectToJson(psTask.getAttribute(), psTaskRemark);
//		psTask.setAttribute(jsonOttributeList);
//		psTask.setReceiveTime(new Date());
//		psTask.setInstallerId(userId);// 释放后无人安装状态
//		Integer result = this.psTaskService.updatePsTask(psTask);
//		if (result != null && result > 0) {
//			responseEntity.initSuccResponseEntity(true, "finish task success");
//			return responseEntity;
//		}
//		responseEntity.initErrorResponseEntity(false, "任务已经被完成");
//		return responseEntity;
//
//	}

}
